﻿using System;
using System.Collections.Generic;
using System.Text;
using Young3.FMSearch.Core.Entities.GameVersions;

namespace Young3.FMSearch.Core.Entities.InGame
{
    public class BaseObject
    {
        public BaseObject(int memoryAddress, IVersion version)
        {
            MemoryAddress = memoryAddress;
            DatabaseMode = DatabaseModeEnum.Realtime;
            Version = version;
        }
        public BaseObject(int memoryAddress, ArraySegment<byte> originalBytes, IVersion version)
        {
            MemoryAddress = memoryAddress;
            OriginalBytes = originalBytes;
            DatabaseMode = DatabaseModeEnum.Cached;
            Version = version;
        }

        public int MemoryAddress;
        public ArraySegment<byte> OriginalBytes;
        public DatabaseModeEnum DatabaseMode;
        public IVersion Version;

        public static bool operator ==(BaseObject a, BaseObject b)
        {
            if (System.Object.ReferenceEquals(a, b))
                return true;

            //cast to object, otherwise there will be a LOOOOONG loop
            if (((object)a == null) || ((object)b == null))
                if ((object)a == null && (object)b == null)
                    return true;
                else
                    return false;

            if (a.MemoryAddress == b.MemoryAddress)
                return true;
            else
                return false;
        }

        public static bool operator !=(BaseObject a, BaseObject b)
        {
            if (!System.Object.ReferenceEquals(a, b))
                return true;

            if (((object)a == null) || ((object)b == null))
                if ((object)a == null && (object)b == null)
                    return false;
                else
                    return true;

            if (a.MemoryAddress != b.MemoryAddress)
                return true;
            else
                return false;
        }

        public override int GetHashCode()
        {
            return this.MemoryAddress.GetHashCode();
        }

        public override bool Equals(object obj)
        {
            return base.GetHashCode().Equals(obj.GetHashCode());
        }
    }
}
